npiperelay & socatでWSLとWindowsのssh-agentを同期
from ssh-agent
from
Windows と WSL2 で同じ SSH key を使用する方法 | 岡山のWEB制作はKOMARI
Windows上のssh-agentをWSL2から利用する - 色々なメモ。
npiperelayをインストール
chocolatey
code:admin powershell
choco install npiperelay
またはReleases · jstarks/npiperelay · GitHubからDL
socatをインストール
code:wsl(sh)
sudo apt install socat
以下を追記
code:~/.bashrc(sh)
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
ss -a | grep -q $SSH_AUTH_SOCK
if $? -ne 0 ; then
rm -f $SSH_AUTH_SOCK
( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"/mnt/c/path/to/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1
fi
/mnt/c/path/to/npiperelay.exeは適宜変更する
code:example
/mnt/c/ProgramData/chocolatey/lib/npiperelay/tools/npiperelay.exe
rupor-github/wsl-ssh-agentで紹介されてるwsl-ssh-agent/wsl-ssh-agent-relay at master · rupor-github/wsl-ssh-agent · GitHubとの違いは?
windows側、WSL側どちらからssh-addしても共有される
WSL側に.ssh/agent.sockというファイルができるが、消してはいけない
WSLでssh-agentを使っているのに秘密鍵のパスワードを聞かれる場合
WindowsのOpenSSHのバージョンが古い
linux - Ssh fails to use private key from ssh-agent: communication with agent failed - Stack Overflow
$ ssh -V
WSL側よりWindows側が古いとcommunicationに失敗する?
Linux.icon
bash.icon